package com.block.job.service;

import cn.hutool.core.util.StrUtil;
import com.block.common.service.LogFactory;
import com.block.db.mapper.SystemRequestTimeRecordMapper;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.slf4j.Logger;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDate;

@Component
public class DeleteRequestTimeRecordJob {

    private static final Logger log = LogFactory.getJobLog();

    @Resource
    SystemRequestTimeRecordMapper systemRequestTimeRecordMapper;

    /**
     * 删除当日前的请求数据记录信息
     * @throws Exception
     */
    @XxlJob("deleteRequestTimeRecordJob")
    public void delete() throws Exception {
        XxlJobHelper.log("删除当日前的请求数据记录信息---------开始执行--------");

        String dateInfo = LocalDate.now().toString();
        Integer integer = systemRequestTimeRecordMapper.deleteLessDataByDateInfo(dateInfo);

        systemRequestTimeRecordMapper.optimizeTable();

        String message = StrUtil.format("删除【time_record】{} ", integer);
        XxlJobHelper.handleSuccess(message);

        XxlJobHelper.log("删除当日前的请求数据记录信息---------结束执行--------"+ message);
    }


    public static void main(String[] args) {
        String dateInfo = LocalDate.now().minusDays(1).toString();
        System.out.println(dateInfo);

    }


}
